<?php

namespace helper;

use think\facade\Db;
use think\facade\Request;

class Form
{
    //获取左侧主菜单
    public function getTextBox($fields){
      $html = '';
      $required = $fields['required'] == 1?' lay-verify="required" ':'';
      $length = '';
      if (isset($fields['maxlength']) && $fields['maxlength']>$fields['minlength']) {
        $length = ' minlength="'.$fields['minlength'].'" maxlength="'.$fields['maxlength'].'" ';
      }
      $attr = $required.$length;
      $setup = $fields['setup'];
      $setup = string2array($setup);
      

      switch ($fields['type']) {
        case 'text':
          $typeStr = 'text';
          if ($setup['ispassword']) {
            $typeStr = 'password';
          }
          $html = '<input type="'.$typeStr.'" name="'.$fields['field'].'" '.$attr.' value="'.$setup['default'].'" placeholder="'.lang('pleaseEnter').$fields['name'].'" class="layui-input '.$fields['class'].'"> ';
          break;
        case 'textarea':
          $html = '<textarea name="'.$fields['field'].'" placeholder="'.lang('pleaseEnter').$fields['name'].'" class="layui-textarea '.$fields['class'].'"></textarea>';
          break;
        default:
          # code...
          break;
      }

      return $html;

    }

}
